package com.sud.config.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

/**
 * 功能：返回对象
 * 作者：SUD
 * 时间：2020/9/4 12:05
 */
@ApiModel(description="返回响应数据")
public class Result<T> implements Serializable {
    @ApiModelProperty(value = "是否成功")
    private boolean success;
    @ApiModelProperty(value = "请求状态")
    private int code;
    @ApiModelProperty(value = "返回对象")
    private T data;
    @ApiModelProperty(value = "错误信息")
    private String message;


    private Result(int code,boolean success, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.success = success;
    }

    public static <T> Result<T> data(T data) {

        return new Result(HttpServletResponse.SC_OK,true,data, "操作成功");
    }

    public static <T> Result<T> error(int code,String message) {
        return new Result(code,false,null, message);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
